﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;

namespace QLKS
{
    public partial class FrmCheckRoom2 : Form
    {
        Controller_CheckIn cont_CheckIn = new Controller_CheckIn();
        Controller_Room cont_room = new Controller_Room();
        public FrmCheckRoom2()
        {
            InitializeComponent();
        }

        public void GetListRoomType()
        {
            DataTable dtRoom = cont_room.ListRoomType().Tables[0];
            cmbRoomType.DataSource = dtRoom;
            cmbRoomType.DisplayMember = "TypeName";
            cmbRoomType.ValueMember = "RoomTypeID";
        }

        private void FrmCheckRoom_Load(object sender, EventArgs e)
        {
            cmbThang.SelectedIndex = DateTime.Now.Month -1;
            cmbNam.Text = DateTime.Now.Year.ToString();
            int thang = int.Parse(cmbThang.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            GetListRoomType();
            string roomTypeID = cmbRoomType.SelectedValue.ToString();
            Load_RoomStatus(thang, nam,roomTypeID);            
        }

        private void Load_RoomStatus(int thang, int nam,string roomtypeID)
        {

            DataSet ds = cont_CheckIn.Select_All_RoomStatus(thang, nam, roomtypeID);
            if(ds.Tables.Count!=0)
                dgvThongKe.DataSource = ds.Tables[0];
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void dgvThongKe_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            String value = "";
            int r = e.RowIndex;
            try
            {
                value = (String)e.Value.ToString().TrimEnd().TrimStart();
            }
            catch (Exception)
            {
            }
            if (value.CompareTo("1") == 0)
            {
                //e.CellStyle.BackColor = Color.PaleGreen; 
                e.CellStyle.BackColor = Color.Red;
                e.Value = "";
            }
            else if (value.CompareTo("0") == 0)
            {
                e.CellStyle.BackColor = Color.PaleGreen;
                e.Value = "";
            }

        }

        private void dgvThongKe_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            if (e.Column.Index == 0)
            {
                e.Column.Width = 29;
            }
            else if (e.Column.Index == 1)
            {
                e.Column.Width = 93;
            }
            else
            {
                e.Column.Width = 24;
            }
        }


        private void btn_check_Click(object sender, EventArgs e)
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            string roomTypeID = cmbRoomType.SelectedValue.ToString();
            Load_RoomStatus(thang, nam, roomTypeID);
        }

        private void cmbThang_DropDownClosed(object sender, EventArgs e)
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            string roomTypeID = cmbRoomType.SelectedValue.ToString();
            Load_RoomStatus(thang, nam, roomTypeID);
        }

        private void cmbRoomType_DropDownClosed(object sender, EventArgs e)
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            string roomTypeID = cmbRoomType.SelectedValue.ToString();
            Load_RoomStatus(thang, nam, roomTypeID);
        }

    }
}
